﻿<?xml version="1.0" encoding="utf-8" ?>
<Feature id="CompanyMembership">
  <BusinessRules>
    <BusinessRule name="getCompanyMemberships" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
    <BusinessRule name="addNewCompanyMembership" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
    <BusinessRule name="updateCompanyMembership" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
    <BusinessRule name="deleteAllCompanyMemberships" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
    <BusinessRule name="deleteCompanyMembership" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
    <BusinessRule name="enrollUserInMembership" security="disabled">
      <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
    </BusinessRule>
	  
	  
	  <BusinessRule name="getCostsTimeType" security="disabled">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>
	  <BusinessRule name="updateMembershipCost" security="disabled">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>
	  <BusinessRule name="getMembershipCosts" security="disabled">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>
	  <BusinessRule name="getCompanyMembershipCostDetail" security="disabled">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>
	  
	  <BusinessRule name="getMembershipVisibility" security="disabled">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>

	  <BusinessRule name="postExtends_getUserMembershipDetail" security="disabled" postExtends="getUser">
		  <LocalClass name="UserManagement.MembershipsBizRules,ScsCore" />
	  </BusinessRule>	  
  </BusinessRules>

  <BusinessObjects>
    <BusinessObject type="CompanyMembership" key="id" extends="UserGroup">
      <Field name="isActive" type="Boolean" />
      <Field name="isDefault" type="Boolean" />
      <Field name="createsNewCompany" type="Boolean" />
      <Field name="userVisibility" type="String" />
      <Field name="minAge" type="Integer" />
	  <Field name="limits" type="UserLimits" />
      <Field name="costs" type="List(MembershipCost)" />
		<Method name="costDescription" language="jscript.NET">
			<![CDATA[
        var ctype = self.getItem("costs");
		if(ctype.numElements > 0)
			return ctype[0].getItem("description");
		return "N/A";
        ]]>
		</Method>
	  <Method name="costType" language="jscript.NET">
			<![CDATA[
        var ctype = self.getItem("costs");
		if(ctype.numElements > 0)
			return ctype[0].getItem("timeType");
		return "N/A";
        ]]>
		</Method>
	  <Method name="costLength" language="jscript.NET">
		  <![CDATA[
        var ctype = self.getItem("costs");
		if(ctype.numElements > 0)
			return ctype[0].getItem("timeLength");
		return "0";
        ]]>
	  </Method>
	  <Method name="costAmount" language="jscript.NET">
		  <![CDATA[
        var ctype = self.getItem("costs");
		if(ctype.numElements > 0)
			return ctype[0].getItem("cost");
		return "0";
        ]]>
	  </Method>
	  <Method name="maxArticlesTotal" language="jscript.NET">
			<![CDATA[
        var limit = self.getItem("limits");
		if(limit.numElements>0)
			return limit.getItem("maxTotalArticles");
		return "0.0";
        ]]>
		</Method>
		<Method name="maxArticlesSize" language="jscript.NET">
			<![CDATA[
        var limit = self.getItem("limits");
		if(limit.numElements>0)
			return limit.getItem("maxTotalArticleSize");
		return "0.0";
        ]]>
		</Method>
	</BusinessObject>
	  
	<BusinessObject type="MembershipCost" key="id">
		<Field name="id" type="Guid" />
		<Field name="description" type="String" />
		<Field name="isDefault" type="Boolean" />
		<Field name="timeLength" type="Integer" />
		<Field name="timeType" type="String" />
		<Field name="cost" type="Currency" />
    </BusinessObject>

    <BusinessObject type="UserMembershipInfo" key="id">
      <Field name="id" type="Guid" />
      <Field name="membership" type="CompanyMembership" />
      <Field name="cost" type="MembershipCost" />
      <Field name="startDate" type="Date" />
      <Field name="endDate" type="Date" />
      <Method name="timeLength" language="jscript.NET">
        <![CDATA[
        var timePeriod = self.getItem("cost.timeLength");
        if(timePeriod == -1)
          timePeriod = "Unlimited";
        return timePeriod;
        ]]>
      </Method>
      <Method name="timeType" language="jscript.NET">
        <![CDATA[
        var timeType = self.getItem("cost.timeType");
        var timeLength = self.getItem("cost.timeLength");
        if(timeLength == -1)
          timeType = "";
        else if(timeType.charAt(timeType.length -1) == 's')
          timeType = timeType.substr(0,timeType.length-1);
        return timeType;
        ]]>
      </Method>
      <Method name="actualCost" language="jscript.NET">
        <![CDATA[
        var cost = self.getItem("cost.cost");
        if(cost == 0.0)
          cost = "nothing";
        return cost;
        ]]>
      </Method>
    </BusinessObject>

    <BusinessObject injects="User">
      <Field name="membership" type="CompanyMembership" />
	  <Field name="membershipCostId" type="Guid" />
	  <Field name="membershipExpires" type="Date" />
	  <Method name="expiresText" language="jscript.NET">
		  <![CDATA[
        var timeType = self.getItem("membershipExpires");
        if("1/1/0001 12:00:00 AM".Equals(timeType.ToString()))
          return "No Expiry";
        return timeType;
        ]]>
	  </Method>	
    </BusinessObject>
	<BusinessObject type="CostTimeType" key="timeType">
		<Field name="timeType" type="String" />
	</BusinessObject>
    <BusinessObject type="MembershipVisibility" key="userVisibility" >
	  <Field name="userVisibility" type="String" />
    </BusinessObject>
	
  </BusinessObjects>

	<ApplicationData>
		<Entry name="membershipsOptions" type="Swaf.Container.FlexiMap" />
		<Entry name="membershipsOptions.visibilities" type="IBizObjList.MembershipVisibility">
			<MembershipVisibilitys>
				<MembershipVisibility userVisibility="New Users" />
				<MembershipVisibility userVisibility="Invitation Only" />
				<MembershipVisibility userVisibility="Active Members Only" />
			</MembershipVisibilitys>
		</Entry>
		<Entry name="membershipsOptions.costTimeTypes" type="IBizObjList.CostTimeType">
			<CostTimeTypes>
				<CostTimeType timeType="Hours" />
				<CostTimeType timeType="Days" />
				<CostTimeType timeType="Weeks" />
				<CostTimeType timeType="Months" />
				<CostTimeType timeType="Years" />
			</CostTimeTypes>
		</Entry>
	</ApplicationData>

  <ApplicationFunctions id="Memberships" description="Company Memberships Management">
    <AppFunction id="ManageCompanyMemberships" description="Manage Company Memberships" />
  </ApplicationFunctions>

</Feature>